name: 'Default Helm Config'
description: "Workflow with Cilium's CLI default config"
inputs:
  image-tag:
    description: "Tag used on all docker images"
    required: true
  chart-dir:
    description: 'Path to Cilium charts directory'
    required: false
    default: 'install/kubernetes/cilium'
outputs:
  cilium_install_defaults:
    description: "Generated values to be used with Cilium CLI"
    value: ${{ steps.set-defaults.outputs.cilium_install_defaults }}
  sha:
    description: "Commit SHA of the images used in the default Cilium CLI values"
    value: ${{ steps.set-defaults.outputs.sha }}
runs:
  using: "composite"
  steps:
    - id: set-defaults
      shell: bash
      run: |
        if [ "${{ github.event_name }}" = "workflow_dispatch" ] || [ ${{ github.event.pull_request }} ] ; then
          SHA="${{ inputs.image-tag }}"
        else
          SHA="${{ github.sha }}"
        fi

        CILIUM_INSTALL_DEFAULTS="--chart-directory=${{ inputs.chart-dir }} \
          --helm-set=debug.enabled=true \
          --helm-set=bpf.monitorAggregation=none"

        # only add SHA to the image tags if it was set
        if [ -n "${SHA}" ]; then
          echo sha=${SHA} >> $GITHUB_OUTPUT
          CILIUM_INSTALL_DEFAULTS+=" --helm-set=image.repository=quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/cilium-ci \
          --helm-set=image.useDigest=false \
          --helm-set=image.tag=${SHA} \
          --helm-set=operator.image.repository=quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/operator \
          --helm-set=operator.image.suffix=-ci \
          --helm-set=operator.image.tag=${SHA} \
          --helm-set=operator.image.useDigest=false \
          --helm-set=clustermesh.apiserver.image.repository=quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/clustermesh-apiserver-ci \
          --helm-set=clustermesh.apiserver.image.tag=${SHA} \
          --helm-set=clustermesh.apiserver.image.useDigest=false \
          --helm-set=hubble.relay.image.repository=quay.io/${{ env.QUAY_ORGANIZATION_DEV }}/hubble-relay-ci \
          --helm-set=hubble.relay.image.tag=${SHA} \
          --helm-set=hubble.relay.image.useDigest=false"
        fi

        if [ -f "${{ inputs.chart-dir }}/../../../.github/actions/helm-default/ci-required-values.yaml" ]; then
          CILIUM_INSTALL_DEFAULTS+=" --values=${{ inputs.chart-dir }}/../../../.github/actions/helm-default/ci-required-values.yaml"
        fi

        echo cilium_install_defaults=${CILIUM_INSTALL_DEFAULTS} >> $GITHUB_OUTPUT
